package com.clock.controller.stage;

import cn.hutool.core.bean.BeanUtil;
import com.clock.common.domain.R;
import com.clock.domain.dto.UserByManagerDTO;
import com.clock.domain.entity.User;
import com.clock.domain.vo.FollowsInfVO;
import com.clock.domain.vo.UserBackVo;
import com.clock.domain.vo.UserCheckInfBackVO;
import com.clock.service.FollowService;
import com.clock.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = {"用户信息接口--只允许用户本人访问"})
@RestController
@RequestMapping("userInf")
public class UserInfController {
    
    @Resource
    UserService userService;

    @ApiOperation(value = "获取用户账户信息", notes = "只需要用户id,返回的值里有用户的角色id，前端帮忙抹掉，别展示出来")
    @PostMapping("getUserInf")
    public R getUserInf(@RequestBody User user){
        User user1 = userService.queryById(user.getUserId().intValue());
        if(user1!=null){
            UserCheckInfBackVO userBackVo = new UserCheckInfBackVO();
            BeanUtil.copyProperties(user1,userBackVo);
            return R.ok(userBackVo);
        }else{
            return R.fail("获取用户信息失败");
        }
    }

    @ApiOperation(value = "更新用户账户信息", notes = "只需要用户id和更新信息---只允许修改用户名和手机号和邮箱")
    @PostMapping("updateUserInf")
    public R updateUserInf(@RequestBody User user){
        String update = userService.update(user);
        if(update == null){
            return R.ok("修改信息成功");
        }else {
            return R.fail(update);
        }
    }

    @ApiOperation(value = "返回用户关注信息", notes = "只需要用户id")
    @PostMapping("getMyFollowsInf")
    public R getMyFollowsInf(@RequestBody User user){
        List<FollowsInfVO> fellowInf = userService.getFellowInf(user);
        if(fellowInf != null){
            return R.ok(fellowInf,"查询成功");
        }else {
            return R.fail("查询失败");
        }
    }


}
